package com.gwm.item.controller;

import com.gwm.item.dto.SpecGroupDTO;
import com.gwm.item.dto.SpecParamDTO;
import com.gwm.item.service.TbSpecGroupService;
import com.gwm.item.service.TbSpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
@Controller
@RequestMapping("/spec")
public class SpecController {

    @Autowired
    private TbSpecGroupService specGroupService;
    @Autowired
    private TbSpecParamService specParamService;

    /**
     * 根据分类id获取分类的规格数据
     * @param id
     * @return
     */
    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> findSpecGroupByCategoryId(@RequestParam(name = "id") Long id){
        List<SpecGroupDTO> groupDTOList = specGroupService.findSpecGroupByCategoryId(id);
        return  ResponseEntity.ok(groupDTOList);
    }

    @GetMapping(value = "/params",name = "根据分类id或组id获取规格参数")
    public ResponseEntity<List<SpecParamDTO>>  findSpecParamByCategoryIdOrGroupId(
            @RequestParam(value = "cid",required = false) Long categoryId,
            @RequestParam(value = "gid",required = false) Long groupId,
            @RequestParam(value = "searching",required = false) Boolean searching
    ){
        List<SpecParamDTO> specParamDTOList = specParamService.findSpecParamByCategoryIdOrGroupId(categoryId,groupId,searching);
        return ResponseEntity.ok(specParamDTOList);
    }





}
